//
//  CouponsTableViewCell.m
//  HTP
//
//  Created by 王鑫 on 15/11/28.
//  Copyright © 2015年 nit. All rights reserved.
//

#import "MyCouponsTableViewCell.h"

#define CELLH ScreenWidth * 1 / 3
#define LINEX (ScreenWidth - 10) / 3
#define LINEH CELLH - 10

@interface MyCouponsTableViewCell ()

@property (nonatomic,strong) UIImageView *backImageView;
//卡卷的优惠额度
@property (nonatomic,strong) UILabel *moneyLabel;
//卡卷使用信息
@property (nonatomic,strong) UILabel *couponInfoLabel;
//可用的时间
@property (nonatomic,strong) UILabel *timeLabel;

@end
@implementation MyCouponsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self _initUI];
    }
    return self;
}

//TODO: cellUI绘制
- (void)_initUI {
    _backImageView = [[UIImageView alloc] init];
    _backImageView.image = [UIImage imageNamed:@"bg_keyong"];
    [self.contentView addSubview:_backImageView];
    
    UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(LINEX, 5, 1, LINEH)];
    lineImage.image = [UIImage imageNamed:@"line_shu"];
    [self.contentView addSubview:lineImage];
    
    _moneyLabel = [[UILabel alloc] init];
    _moneyLabel.font = [UIFont systemFontOfSize:16];
    _moneyLabel.textColor = [UIColor orangeColor];
    [self.contentView addSubview:_moneyLabel];
    
    UIImageView *pointImageView_1st = [[UIImageView alloc] initWithFrame:CGRectMake(LINEX + 10, (CELLH - 30) / 2.0 + 2, 5, 5)];
    [pointImageView_1st.layer setCornerRadius:2.5];
    pointImageView_1st.image = [UIImage imageNamed:@"judian"];
    [self.contentView addSubview:pointImageView_1st];
    
    _couponInfoLabel = [[UILabel alloc] init];
    _couponInfoLabel.font = [UIFont systemFontOfSize:14];
    _couponInfoLabel.textColor = RGBCOLOR(101, 101, 101, 1);
    [self.contentView addSubview:_couponInfoLabel];
    
    UIImageView *pointImageView_2nd = [[UIImageView alloc] initWithFrame:CGRectMake(LINEX + 10, (CELLH - 30) / 2.0 + 29, 5, 5)];
    [pointImageView_2nd.layer setCornerRadius:2.5];
    pointImageView_2nd.image = [UIImage imageNamed:@"judian"];
    [self.contentView addSubview:pointImageView_2nd];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = [UIFont systemFontOfSize:14];
    _timeLabel.textColor = RGBCOLOR(101, 101, 101, 1);
    [self.contentView addSubview:_timeLabel];
    
}


//TODO: 控件位置设置
- (void)layoutSubviews {
    
    [_backImageView setFrame:CGRectMake(5, 0, ScreenWidth - 10, CELLH)];
    [_moneyLabel setFrame:CGRectMake(10, 10, LINEX - 5, CELLH - 20)];
    [_couponInfoLabel setFrame:CGRectMake(LINEX + 20, (CELLH - 30) / 2.0 - 0.5, ScreenWidth - LINEX - 25, 10)];
    [_timeLabel setFrame:CGRectMake(LINEX + 20, (CELLH - 30) / 2.0 + 26.5, ScreenWidth - LINEX - 25, 10)];
}

//TODO: 数据设置
- (void)setData:(id)coupon {
    MyCouponsModel *couponsInfo = (MyCouponsModel *)coupon;
    
    if ([couponsInfo.isUsed intValue] == 1) {
        _backImageView.image = [UIImage imageNamed:@"bg_bukeyong"];
    }
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥ %.2f",[couponsInfo.couponsValue floatValue]]];
    NSInteger lenght = [NSString stringWithFormat:@"￥ %.2f",[couponsInfo.couponsValue floatValue]].length;
    [str addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(2, lenght - 4)];
    _moneyLabel.attributedText = str;
    
    _couponInfoLabel.text = couponsInfo.couponsContent;
    _timeLabel.text = [NSString stringWithFormat:@"%@ 至 %@",couponsInfo.startTime,couponsInfo.stopTime];
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
